using System;
using System.Collections.Generic;
using System.Text;
using OgilvyOne.IDAL;
using OgilvyOne.Model;
using System.Collections;

namespace OgilvyOne.BLL.SysManage
{
    public class Privilege
    {
        // Methods
        public bool CheckUserPrivilege(int iUserID, int iMenuID, int iKeyValue)
        {
            int num = OgilvyOne.DALFactory.Privilege.Create().getValueByUserID(iUserID, iMenuID);
            if (num < 2)
            {
                SysMenu menu = new SysMenu();
                SysMenuInfo info = (SysMenuInfo)menu.getCurrMenuNode(iMenuID)[0];
                int num2 = info.Parent_Node_ID;
                if (num2 > 0)
                {
                    num = this.getParentValueByUser(iUserID, num2);
                }
            }
            bool flag = false;
            if ((num % iKeyValue) == 0)
            {
                flag = true;
            }
            return flag;
        }

        public int getParentValueByUser(int iUserID, int iMenuID)
        {
            int num = OgilvyOne.DALFactory.Privilege.Create().getValueByUserID(iUserID, iMenuID);
            if (num < 2)
            {
                SysMenu menu = new SysMenu();
                SysMenuInfo info = (SysMenuInfo)menu.getCurrMenuNode(iMenuID)[0];
                int num2 = info.Parent_Node_ID;
                if (num2 > 0)
                {
                    num = this.getParentValueByUser(iUserID, num2);
                }
            }
            return num;
        }

        public int getPrivilegeValue(int iRoleID, int iMenuID)
        {
            return OgilvyOne.DALFactory.Privilege.Create().getPrivilegeValue(iRoleID, iMenuID);
        }

        public int getValueByUserID(int iUserID, int iMenuID)
        {
            return OgilvyOne.DALFactory.Privilege.Create().getValueByUserID(iUserID, iMenuID);
        }

        public int Insert(PrivilegeInfo newInfo)
        {
            if (string.IsNullOrEmpty(newInfo.MenuKeyStr))
            {
                return 0;
            }
            return OgilvyOne.DALFactory.Privilege.Create().Insert(newInfo);
        }

    }
}
